#include <stdio.h>
#include <malloc.h>
void sort(char *c,int length)
{
	int tempIndex = 0;
	for(int i = 0;i < length - 1;i++)
	{
		tempIndex = i;
		for(int j = i + 1;j < length;j++)
		{
			if(c[tempIndex] > c[j])
			{
				tempIndex = j;
			}
		}
		if(tempIndex != i)
		{
			c[tempIndex] = c[tempIndex] ^ c[i];
			c[i] = c[tempIndex] ^ c[i];
			c[tempIndex] = c[tempIndex] ^ c[i];
		}
	}
}
int main(int argc,char *argv[])
{
	if(argc < 4)
	{
		printf("prmeter error\n");
		return 1;
	}
	FILE *fp1 = fopen(argv[1],"r");
	FILE *fp2 = fopen(argv[2],"r");
	FILE *fp3 = fopen(argv[3],"w");
	if(fp1 == NULL || fp2 == NULL || fp3 == NULL)
	{
		printf("fail to open file \n");
		return 1;
	}
	char *c = NULL,temp;
	int length = 0;
	while((temp = fgetc(fp1)) != EOF)
	{
		c = realloc(c,++length);
		c[length - 1] = temp;
	}
	sort(c,length);
	//printf("%s\n",c);
	for(int i = 0;i < length;i++)
	{
		fputc(c[i],fp3);
	}
	fclose(fp1);
	fclose(fp2);
	fclose(fp3);
	return 0;
}
